package com.example.yqand4v1_1.controller;

import com.example.yqand4v1_1.beans.Result;
import com.example.yqand4v1_1.dao.entity.News;
import com.example.yqand4v1_1.dto.NewsCollectDTO;
import com.example.yqand4v1_1.service.NewsCollectService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/newsCollect")
public class NewsCollectController {

    @Resource
    private NewsCollectService newsCollectService;

    // 新闻收藏
    @PostMapping(value = "/collect")
    public Result<Void> collect(@RequestBody NewsCollectDTO newsCollectDTO) {
        newsCollectService.collect(newsCollectDTO);
        return Result.success();
    }

    // 新闻取消收藏
    @PostMapping(value = "/removeCollect")
    public Result<Void> removeCollect(@RequestBody NewsCollectDTO newsCollectDTO) {
        newsCollectService.removeCollect(newsCollectDTO.getUserId(), newsCollectDTO.getNewsId());
        return Result.success();
    }

    // 获取新闻收藏列表
    @GetMapping(value = "/list/{id}")
    public Result<List<News>> list(@PathVariable("id") int userId) {
        return Result.success(newsCollectService.list(userId));
    }
}
